package com.openscorer;

import android.app.Activity;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TableRow;
import android.widget.TextView;

public class IntSetter implements TextWatcher {
	TableRow layout_;
	TextView prompt_;
	EditText value_;
	Button confirm_;
	Int i_;
	ScoreDisplay display_;
	
	public IntSetter(Activity activity, Int i, ScoreDisplay display) {
		i_ = i;
		display_ = display;
		layout_ = (TableRow) TableRow.inflate(activity, R.layout.intsetter, null);
		prompt_ = (TextView) layout_.findViewById(R.id.Prompt);
		prompt_.setText(i.getName());
		value_ = (EditText) layout_.findViewById(R.id.Text);
		value_.addTextChangedListener(this);
	}

	public View View() {
		return layout_;
	}

	public void onTextChanged(CharSequence s, int start, int before, int count) {
	}

	public void afterTextChanged(Editable s) {
		try {
			i_.setValue(Integer.parseInt(value_.getText().toString()));
		} catch (NumberFormatException e) {
		}
		display_.updateScore();
	}

	public void beforeTextChanged(CharSequence s, int start, int count,
			int after) {
	}

}
